package GUI;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;

public class MenuPanel extends JPanel implements ActionListener{

	private static final long serialVersionUID = 1L;
	private JButton playButton;
	//private JButton rankingButton;
	private JButton creditosButton;
	private MainFrame frame;
	private InvadersPanel invadersPanel;
	private CreditsPanel creditosPanel;
	
	public MenuPanel(MainFrame frame) {
		this.frame = frame;
		setPreferredSize(new Dimension(800,600));
		setVisible(true);
    	setLayout(null);
    	playButton = new JButton(new ImageIcon(getClass().getResource("/Sprites/playRelease.png")));
    	add(playButton);
    	playButton.setBounds(250, 240, 293,50);
    	playButton.addActionListener(this);

    	/*
		rankingButton = new JButton(new ImageIcon(getClass().getResource("/Sprites/rankingRelease.png")));
		add(rankingButton);
		rankingButton.setBounds(250, 300, 293,50);
		rankingButton.addActionListener(this);
		*/
		
		creditosButton = new JButton(new ImageIcon(getClass().getResource("/Sprites/creditosRelease.png")));
		add(creditosButton);
		creditosButton.setBounds(250, 300, 293,50);
		creditosButton.addActionListener(this);
		
		JPanel panelPaint = new JPanel() {
			
			private static final long serialVersionUID = 1L;

			public void paintComponent(Graphics g) {  
		        super.paintComponents(g);
		        g.drawImage(new ImageIcon(getClass().getResource("/Sprites/menu.png")).getImage(),0,0,null);
		        g.drawImage(new ImageIcon(getClass().getResource("/Sprites/logoAsgardDefender.png")).getImage(),140,-20,null);
		        g.drawImage(new ImageIcon(getClass().getResource("/Sprites/logoGUILDJ.png")).getImage(),580,460,null);
		       
		    }
		};
		
		add(panelPaint);
		panelPaint.setBounds(0, 0, 800,600);
	
	}
	
	public void actionPerformed(ActionEvent e) {
		//Lanca o jogo
		if(e.getSource() == playButton) {
			this.setVisible(false);
			invadersPanel = new InvadersPanel(frame, this);
			frame.setInvadersPanel(invadersPanel); 
			frame.getContentPane().add(invadersPanel);
			frame.getInvadersPanel().setVisible(true);
			//frame.getContentPane().add(invadersPanel);
			invadersPanel.requestFocus();
			frame.pack();
		}
		//Lanca os creditos
		if(e.getSource() == creditosButton) {
				this.setVisible(false);
				creditosPanel = new CreditsPanel(frame, this);
				frame.getContentPane().add(creditosPanel);
				creditosPanel.requestFocus();
				frame.pack();
		}
	}
}
